package leetcode_day._2022._202209._2130;

/**
 * 面试题 01.02. 判定是否互为字符重排
 * 算法：模拟
 *
 * @author yzh
 * @version 1.0
 * @date 2022/9/27 23:00
 */
public class _27_面试0102 {

    public boolean CheckPermutation(String s1, String s2) {
        int n = s1.length(), m = s2.length();
        if (n != m) return false;
        char[] cs = new char[256];
        int tot = 0;
        for (int i = 0; i < n; i++) {
            if (++cs[s1.charAt(i)] == 1) ++tot;
            if (--cs[s2.charAt(i)] == 0) --tot;
        }
        return tot == 0;
    }

}
